# -*-coding:Utf-8 -*
""" UI Color Class
"""
import mathutils

class Color(mathutils.Color):
	def __init__(self, args):
		mathutils.Color.__init__(self)
		self._a = 1.0
			
	def convertValue(self, value):
		if type(value) == int:
			value = value/255
			if value > 1.0:
				value = 1.0
		elif type(value) == str:
			value = float(value)
		if type(value) == float:
			if value < 0:
				value *= -1
			return value
		return 0.0
		
	@property
	def a(self):
		return self._a
	@a.setter
	def a(self, value):
		if type(value) == int:
			value = value/255
			if value > 1.0:
				value = 1.0
		elif type(value) == str:
			value = float(value)
		if type(value) == float:
			if value < 0:
				value *= -1
			self._a = value
		return self
		
	@property
	def all(self):
		return (self.r,self.g,self.b,self.a)
"""
class Color(object):
	def __init__(self, *args):
		self._color = [0.0,0.0,0.0,1.0]
		if len(args)>0 and type(args[0]) in [list, tuple]:
			args = args[0]
		if len(args)>0:
			self._color[0] = self.convertValue(args[0])
		if len(args)>1:
			self._color[1] = self.convertValue(args[1])
		if len(args)>2:
			self._color[2] = self.convertValue(args[2])
		if len(args)>3:
			self._color[3] = self.convertValue(args[3])
	
	def convertValue(self, value):
		if type(value) == int:
			value = value/255
			if value > 1.0:
				value = 1.0
		elif type(value) == str:
			value = float(value)
		if type(value) == float:
			if value < 0:
				value *= -1
			return value
		return 0.0
	
	@property
	def all(self):
		return tuple(self._color)
	@property
	def r(self):
		return self._color[0]
	@property
	def g(self):
		return self._color[1]
	@property
	def b(self):
		return self._color[2]
	@property
	def a(self):
		return self._color[3]
	@r.setter
	def setr(self, value):
		if type(value) == int:
			value = value/255
			if value > 1.0:
				value = 1.0
		elif type(value) == str:
			value = float(value)
		if type(value) == float:
			if value < 0:
				value *= -1
			self._color[0] = value
	@g.setter
	def setg(self, value):
		if type(value) == int:
			value = value/255
			if value > 1.0:
				value = 1.0
		elif type(value) == str:
			value = float(value)
		if type(value) == float:
			if value < 0:
				value *= -1
			self._color[1] = value
	@b.setter
	def setb(self, value):
		if type(value) == int:
			value = value/255
			if value > 1.0:
				value = 1.0
		elif type(value) == str:
			value = float(value)
		if type(value) == float:
			if value < 0:
				value *= -1
			self._color[2] = value
	@a.setter
	def seta(self, value):
		if type(value) == int:
			value = value/255
			if value > 1.0:
				value = 1.0
		elif type(value) == str:
			value = float(value)
		if type(value) == float:
			if value < 0:
				value *= -1
			self._color[3] = value
"""
COLOR_BLACK = Color((0.0,0.0,0.0))
COLOR_WHITE = Color((1.0,1.0,1.0))
